<div id="app">
    <section class="content-header">
        <h1>
            <small>渠道列表</small>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a href="/admin/channel/add" class="btn btn-sm btn-default" title="添加渠道"> <span class="hidden-xs">添加渠道</span></a>
                            </div>
                        </div>

                        <span>


    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>

    <div class="btn-group" style="margin-right: 10px" data-toggle="buttons">
        <label class="btn btn-sm btn-dropbox shaixuan-filter-btn" title="筛选">
            <input type="checkbox"><i class="fa fa-filter"></i><span class="hidden-xs">筛选</span>
        </label>
    </div>
  </span>
                    </div>

                    <!--   筛选开始   -->
                    <div class="box-header with-border hide" id="filter-box">
                        <form action="/admin/channel/index" class="form-horizontal" pjax-container method="get">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="box-body">
                                        <div class="fields-group">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 渠道id</label>
                                                <div class="col-sm-8">
                                                    <div class="input-group input-group-sm">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-pencil"></i>
                                                        </div>

                                                        <input type="text" class="form-control cha_id" placeholder="渠道id" name="cha_id" value="@if(!empty($where['cha_id'])) {{$where['cha_id']}} @endif">
                                                    </div>    </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 品牌名称</label>
                                                <div class="col-sm-8">
                                                    <div class="input-group input-group-sm">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-pencil"></i>
                                                        </div>

                                                        <input type="text" class="form-control cha_name" placeholder="渠道名称" name="cha_name" value="@if(!empty($where['cha_name'])) {{$where['cha_name']}} @endif">
                                                    </div>    </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"> 渠道状态</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control cha_status" id="cha_status" name="cha_status" style="width: 100%;">
                                                        <option value="-1"></option>
                                                        <option value="1">待上架</option>
                                                        <option value="2">已上架</option>
                                                        <option value="3">已下架</option>
                                                        <option value="4">已删除</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-body -->

                            <div class="box-footer">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="col-md-2"></div>
                                        <div class="col-md-8">
                                            <div class="btn-group pull-left">
                                                <button class="btn btn-info submit btn-sm"><i
                                                            class="fa fa-search"></i>&nbsp;&nbsp;搜索</button>
                                            </div>
                                            <div class="btn-group pull-left " style="margin-left: 10px;">
                                                <a href="/admin/channel/index" class="btn btn-default btn-sm"><i
                                                            class="fa fa-undo"></i>&nbsp;&nbsp;重置</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--筛选结束-->



                    <!-- /.box-header -->
                    <!--数据列表开始   -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead >
                            <tr >
                                <th>渠道id</th>
                                <th>渠道名称</th>
                                <th>渠道描述</th>
                                <th>渠道状态</th>
                                <th>appid</th>

                                <th>首页是否有排版</th>
                                <th>logo</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>

                            @if (!empty($data['data']))
                                @foreach($data['data'] as $v)
                                    <tr >
                                        <td >
                                            {{ $v['cha_id'] }}
                                        </td>
                                        <td >
                                            {{$v['cha_name']}}
                                        </td>
                                        <td >
                                            {{$v['cha_describe']}}
                                        </td>
                                        <td >
                                            @if($v['cha_status']==1)
                                             待上架
                                            @elseif($v['cha_status']==2)
                                                已上架
                                            @elseif($v['cha_status']==3)
                                                已下架
                                            @else
                                                已删除
                                            @endif
                                        </td>
                                        <td >
                                            {{$v['app_id']}}
                                        </td>

                                        <td >
                                            @if($v['is_typ']==1)
                                                <button data-type="is_typ" onclick="del(this,{{$v['cha_id']}})" style="color:red;">否</button>
                                            @else
                                                <button data-type="is_typ" onclick="del(this,{{$v['cha_id']}})" style="color:blue;">是</button>
                                            @endif
                                        </td>

                                        <td >
                                            <img src="{{$url}}{{$v['logo']}}" width="100">
                                        </td>

                                        <td >

                                            <a href="/admin/homePage/index?cha_id={{$v['cha_id']}}">
                                                排版
                                            </a>

                                            <a href="/admin/channel/edit?cha_id={{$v['cha_id']}}">
                                                编辑
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <!--数据列表结束-->



                    <!-- 分页开始    -->
                    <div class="box-footer clearfix">
                        @if($data['data'])
                            从 <b>{{$data['from']}}</b> 到 <b>{{$data['to']}}</b> ，总共 <b>{{$data['total']}}</b> 条
                            <ul class="pagination pagination-sm no-margin pull-right">
                                <!-- Previous Page Link -->
                                @if($data['page_list'])
                                    <li class="page-item @if($data['current_page']==1) disabled @endif ">
                                        @if($data['current_page']>1)
                                            <a class="page-link" data-href="{{$data['page_url']}}&page={{$data['up_page']}}" rel="next">&laquo;</a>
                                        @else
                                            <span class="page-link">&laquo;</span>
                                        @endif</li>
                                    @foreach($data['page_list'] as $v)
                                        @if($v=='...')
                                            <li class="page-item disabled"><span class="page-link">{{$v}}</span></li>
                                        @endif
                                        @if($v==$data['current_page'])
                                            <li class="page-item active"><span class="page-link">{{$v}}</span></li>
                                        @elseif($v!='...')
                                            <li class="page-item"><a class="page-link" data-href="{{$data['page_url']}}&page={{$v}}">{{$v}}</a></li>
                                        @endif
                                    @endforeach
                                    <li class="page-item @if($data['current_page']==$data['last_page']) disabled @endif ">
                                        @if($data['current_page']<$data['last_page'])
                                            <a class="page-link" data-href="{{$data['page_url']}}&page={{$data['next_page']}}" rel="next">&raquo;</a>
                                        @else
                                            <span class="page-link">&raquo;</span>
                                        @endif</li>
                                @endif
                            </ul>

                            <label class="control-label pull-right" style="margin-right: 10px; font-weight: 100;">
                                <small>显示</small>&nbsp;
                                <select class="input-sm grid-per-pager" name="per-page">
                                    <option value="{{$data['page_url']}}&per_page=10" >10</option>
                                    <option value="{{$data['page_url']}}&per_page=20" selected>20</option>
                                    <option value="{{$data['page_url']}}&per_page=30" >30</option>
                                    <option value="{{$data['page_url']}}&per_page=50" >50</option>
                                    <option value="{{$data['page_url']}}&per_page=100" >100</option>
                                </select>
                                &nbsp;<small>条</small>
                            </label>
                        @else
                            <div style="text-align: center;margin:20px;">未查到数据</div>
                        @endif
                    </div>
                    <!-- 分页结束    -->

                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>

<script data-exec-on-popstate>

    $(function () {
        $("#cha_status").val("@if(!empty($where['cha_status'])){{$where['cha_status']}}@endif");

        //tr选中样式控制
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });

        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });

        //搜索
        $('.shaixuan-filter-btn').unbind('click');
        $('.shaixuan-filter-btn').click(function (e) {
            if ($('#filter-box').is(':visible')) {
                $('#filter-box').addClass('hide');
            } else {
                $('#filter-box').removeClass('hide');
            }
        });
        @if($where)
        $('#filter-box').removeClass('hide');
        @endif

        //改变分页量
        $('.grid-per-pager').on("change", function(e) {
            $.pjax({url: this.value, container: '#pjax-container'});
        });

        //分页
        $("a.page-link").click(function(e){
            var url=$(this).attr('data-href');
            $.pjax({url:url, container: '#pjax-container'});
        })
    });

    //删除或不删除
    function del(e,id){
        var type=$(e).attr('data-type');
        $.ajax({
            url:"/admin/channel/ajaxFieldsEdit",
            data:{cha_id:id,_token:LA.token,},
            type:'post',
            dataType:'json',
            success:function(m){
                if(m.status==1){
                    if(m.data.zhi==1){
                        $(e).html('否').css("color",m.data.color);
                    }else{
                        $(e).html('是').css("color",m.data.color);
                    }
                    toastr.success('ok');
                }else{
                    toastr.error(m.message);
                }
            }
        });
    }
</script>